package com.fyp.ptma.dao.service;

import java.util.List;

import javax.persistence.PersistenceException;

import org.hibernate.HibernateException;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fyp.ptma.dao.repository.irepository.IDownloaderDao;
import com.fyp.ptma.dao.service.iservice.IDownloaderService;
import com.fyp.ptma.model.Application;
import com.fyp.ptma.model.Downloader;
import com.fyp.ptma.model.Installation;

@Service
public class DownloaderService implements IDownloaderService {
	@Autowired
	private IDownloaderDao downloaderDao;

	@Transactional
	public Long save(Object objToSave) throws PersistenceException,
			ConstraintViolationException {
		// TODO Auto-generated method stub
		return downloaderDao.save(objToSave);
	}

	@Transactional
	public Long update(Object objToUpdate) throws PersistenceException {
		// TODO Auto-generated method stub
		return downloaderDao.update(objToUpdate);
	}

	@Transactional
	public boolean delete(Object objToDelete) throws PersistenceException,
			ConstraintViolationException {
		// TODO Auto-generated method stub
		return downloaderDao.delete(objToDelete);
	}

	@Transactional
	public List<Application> getAllApplications(Downloader downloader)
			throws HibernateException {
		return downloaderDao.getAllApplications(downloader);
	}

	@Transactional
	public Downloader getDownloaderByEmailAndDeviceId(Downloader downloader)
			throws HibernateException {
		return downloaderDao.getDownloaderByEmailAndDeviceId(downloader);
	}

	@Transactional
	public Long saveOrUpdate(Installation installation)
			throws HibernateException {
		// TODO Auto-generated method stub
		return downloaderDao.saveOrUpdate(installation);
	}

	@Transactional
	public Long saveOrUpdate(Downloader downloader) throws HibernateException {
		// TODO Auto-generated method stub
		return downloaderDao.saveOrUpdate(downloader);
	}

	@Transactional
	public List<Downloader> getDownloadersByDeviceIds(List<String> deviceIds,
			String authEmail) throws HibernateException {
		// TODO Auto-generated method stub
		return downloaderDao.getDownloadersByDeviceIds(deviceIds, authEmail);
	}

	@Transactional
	public void saveOrUpdate(Object objToSave) throws PersistenceException,
			ConstraintViolationException {
		downloaderDao.saveOrUpdate(objToSave);

	}

	@Transactional
	public Installation getInstallation(Installation ins)
			throws HibernateException {
		return downloaderDao.getInstallation(ins);
	}

	@Transactional
	public Downloader getDownloaderByDeviceId(Downloader deviceId)
			throws HibernateException {
		return downloaderDao.getDownloaderByDeviceId(deviceId);

	}
}
